package cn.jia.hrm.controller;

import cn.jia.hrm.AjaxResult;
import cn.jia.hrm.CourseDoc;
import cn.jia.hrm.CourseESQuery;
import cn.jia.hrm.PageList;
import cn.jia.hrm.service.ISearchService;
import org.aspectj.weaver.loadtime.Aj;
import org.elasticsearch.search.SearchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/es")
public class SearchController {
    @Autowired
    private ISearchService searchService;

    /*将发布的课程保存课程到es*/
    @PostMapping("/search")
    @PreAuthorize("hasAuthority('es:saveCourse')")
    public AjaxResult save(@RequestBody CourseDoc courseDoc){
        searchService.save(courseDoc);
        return AjaxResult.me();
    }

    @PostMapping("/searchCourse")
    public AjaxResult searchCourse(@RequestBody CourseESQuery query){
        PageList pageList= searchService.searchCourse(query);
        return AjaxResult.me().setResultObj(pageList);
    }


    @PostMapping("/offLine/{id}")
    AjaxResult delete(@PathVariable Long id ){
        searchService.delete(id);
        return AjaxResult.me();
    }
}
